﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles{
    <style>
        #dictTable + .layui-table-view .layui-table-tool-temp {
            padding-right: 0;
        }

        #dictTable + .layui-table-view .layui-table-body tbody > tr td {
            cursor: pointer;
        }

        #dictTable + .layui-table-view .layui-table-body tbody > tr.layui-table-click {
            background-color: #fff3e0;
        }

        #dictTable + .layui-table-view .layui-table-body tbody > tr.layui-table-click td:last-child > div:before {
            position: absolute;
            right: 6px;
            content: "\e602";
            font-size: 12px;
            font-style: normal;
            font-family: layui-icon !important;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        #dictTable .layui-btn-container {
            margin-bottom: 0px;
        }
    </style>
}
<div class="body-list">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-body" style="padding: 5px;">
                        <form class="layui-form ok-search">
                            <input class="layui-input" autocomplete="off" id="bizetype" placeholder="请输入业务类型" name="bizetype">
                            <input type="hidden" id="btid" />
                            <button class="layui-btn layui-btn-color" lay-submit="" lay-filter="searchtype">
                                <i class="layui-icon layui-icon-search"></i>
                            </button>
                        </form>
                        @{ await Html.RenderPartialAsync("_ToolbarAuthTpl", new SystemFunctionModel
                            {
                                MenuKey = SysMenuConstant.MENU_FILES_MANAGE,
                                FunDictionary = new Dictionary<string, string> { { "Add", "业务" }, { "Update", "修改" }, { "Delete", "删除" } }
                            });
                        }
                        <!-- 数据表格1 -->
                        <table id="dictTable" lay-filter="dictTable"></table>
                    </div>
                </div>
            </div>
            <div class="layui-col-md9">
                <div class="layui-card">
                    <div class="layui-card-body" style="padding: 5px;">
                        <!-- 表格工具栏2 -->
                        <form class="layui-form ok-search " id="form_info">
                            <input name="foname" class="layui-input" placeholder="输入文件原始名称" />
                            <button class="layui-btn layui-btn-color" lay-submit="" lay-filter="search">
                                <i class="layui-icon layui-icon-search"></i>
                            </button>
                            <input type="hidden" id="bizetypeid" name="bizetype" />
                        </form>
                         @{ await Html.RenderPartialAsync("_ToolbarAuthTpl", new SystemFunctionModel
                            {
                                Num=2,
                                MenuKey = SysMenuConstant.MENU_FILES_MANAGE,
                                FunDictionary = new Dictionary<string, string> {{ "Delete", "删除" } }
                            });
                        }
                        <!-- 数据表格2 -->
                        <table id="dictDataTable" lay-filter="dictDataTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<!-- 操作列 -->
@{
    await Html.RenderPartialAsync("_OperationTpl", new SystemFunctionModel
    {
        MenuKey = SysMenuConstant.MENU_FILES_MANAGE,
        FunDictionary = new Dictionary<string, string> { { "Delete", "删除" } }
    });
}

<script type="text/html" id="TbState">
    <span class="icon-text" style="cursor: pointer;" data-fszie="{{d.Fslimit}}" data-flimit="{{d.Ftlimit}}">
        {{d.Bizetype}}&nbsp;<i class="layui-icon layui-icon-tips"></i>
    </span>
</script>
@section scripts{
    <script>
        layui.use(["element", "form", "okLayer", "okUtils", "table"], function () {
            var form = layui.form;
            var util = layui.util;
            var okLayer = layui.okLayer;
            var okUtils = layui.okUtils;
            var table = layui.table;
            util.fixbar({});
            var selObj;  // 左表选中数据

            okLoading.close();
            var insTb = table.render(
                lscom.TableRenderOption({
                    elem: '#dictTable',
                    url: '/Systems/Files/GetAllFilesConfig',
                    defaultToolbar: [],
                    height: 'full-120',
                    page: {
                        layout: ['limit', 'count', 'prev', 'page', 'next'] //自定义分页布局
                        , groups: 3 //只显示 1 个连续页码
                        , limit: 20
                        , limits: [10, 20, 30, 50]
                        , first: false //不显示首页
                        , last: false //不显示尾页
                    },
                    cols: [[
                        { type: 'numbers' },
                        { field: 'Bizetype', title: '业务类型', toolbar: "#TbState",width:"40%" },
                        { field: 'Savepath', title: '存储路径',width:"49%" }
                    ]],
                    done: function (res, curr, count) {
                        if (res.data.length == 0) {
                            insTb2.reload({ data: [], url: '' });
                        } else {
                            $('#dictTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
                        }
                        $(".icon-text").on("click", function (e) {
                            var that = this;
                            var fsize = $(that).data("fszie");
                            var flimit = $(that).data("flimit");
                            layer.tips('大小限制：'+(fsize==null?"无":fsize)+"<br/>类型限制："+(flimit==null?"无":flimit), that, lscom.layertipOpt);
                            e.stopPropagation();
                        });
                    }
                }));

            form.on("submit(searchtype)", function (data) {
                insTb.reload({ where: data.field });
                return false;
            });
            lscom.registerclick([{ id: "Add", fun: function () { add(0);} },
                { id: "Update", fun: function () { edit(0, $("#btid").val());} }, { id: "Delete", fun: function () { batchDel();} }]);
          

            function batchDel() {
                okLayer.confirm("确定要删除吗？", function (index) {
                    layer.close(index);
                    okUtils.ajax("/Systems/Files/DelFileConf", "post", { ids: $("#btid").val() }).done(function (response) {
                        if (response.code == 0) {
                            okLayer.greenTickMsg(response.msg, function () {
                                insTb.reload();
                                // $('#dictTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
                            });

                        } else {
                            okLayer.redCrossMsg(response.msg)
                        }

                    }).fail(function (error) {
                        console.log(error)
                    });
                });
            }

            function edit(tp, id) {
                if (tp == 0) {
                    okLayer.open("编辑文件配置", '/Systems/Files/EditFileConf?id=' + id, "600px", "425px", null, function () {
                        insTb.reload();
                    });
                }
            }

            function add(tp) {
                if (tp == 0) {
                    okLayer.open("新增文件配置", '/Systems/Files/CreatFileConf', "600px", "425px", null, function () {
                        insTb.reload();
                    })
                }
            }

            function del(op, id) {
                if (op == 0) {
                    id = okUtils.tableBatchCheck(table);
                }
                if (id) {
                    lscom.treeTableRenderDel(op, id, "/Systems/Files/DelFile", okLayer, okUtils, function () { insTb2.reload(); })
                }

            }

            /* 监听行单击事件 */
            table.on('row(dictTable)', function (obj) {
                selObj = obj;
                obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                $("#bizetypeid").val(obj.data.Bizetype);
                $("#btid").val(obj.data.Id);
                insTb2.reload({ where: { bizetype: obj.data.Bizetype }, page: { curr: 1 }, url: '/Systems/Files/GetAllFiles' });
            });

            var insTb2 = table.render(
                lscom.TableRenderOption(
                    {
                        elem: '#dictDataTable',
                        data: [],
                         height: 'full-120',
                        cols: [[
                            { type: 'checkbox' },
                            { field: 'Bizetype', title: '业务名称', sort: true },
                            { field: 'Foname', title: '原始名称', sort: true },
                            { field: 'Fpath', title: '文件路径' },
                            { field: 'Fsize', title: '文件大小', sort: true },
                            { field: 'Ftype', title: '文件类型' },
                            {
                                field: 'Createdate', title: '创建时间', templet: function (d) {
                                    return util.toDateString(d.createTime);
                                }, sort: true
                            },
                            { title: '操作', toolbar: '#operationTpl', align: 'center', width: 80, minWidth: 80 }
                        ]],
                        done: function (res, curr, count) {

                        }
                    }));
            //监听排序事件
            table.on('sort(dictDataTable)', function (obj) {
                var data = $("#form_info").serializeJson();
                data.field = obj.field;
                data.order = obj.type;
                insTb2.reload({
                    where: data,
                    page: { curr: 1 },
                    url: '/Systems/Files/GetAllFiles',
                });

            });

            form.on("submit(search)", function (data) {
                insTb2.reload({ where: data.field });
                return false;
            });

           
            lscom.registerclick([{ id: "Delete", fun: function () { del(0); } }],2);
            table.on('tool(dictDataTable)', function (obj) {
                var data = obj.data;
                switch (obj.event) {
                    case "Update":
                        edit(1, data.Id);
                        break;
                    case "Delete":
                        del(1, data.Id);
                        break;
                }
            });
        })
    </script>
}
